package pl.edu.agh.student.janikhankus.earley;

import pl.edu.agh.student.janikhankus.tree.Symbol;

public class Tuple implements Comparable<Object> {
	Symbol symbol;
	int num;

	public Tuple(Symbol symbol, int i) {
		this.symbol = symbol;
		this.num = i;
	}

	public Symbol getSymbol() {
		return symbol;
	}

	public int getNum() {
		return num;
	}

	@Override
	public int hashCode() {
		return (new Integer(num)).hashCode();
	}

	@Override
	public int compareTo(Object o) {
		if (!(o instanceof Tuple) || o == null) {
			return 1;
		}
		Tuple t = (Tuple) o;
		if (this.symbol == null || t.getSymbol() == null) {
			if (this.symbol != t.getSymbol())
				return 1;
		} else {
			if (!(this.symbol.getName().equals(t.getSymbol().getName())))
				return 1;
		}
		if (this.num == t.getNum()) {
			return 0;
		}
		return 0;
	}

	@Override
	public boolean equals(Object o) {

		if (!(o instanceof Tuple) || o == null) {
			return false;
		}
		Tuple t = (Tuple) o;

		if (this.symbol == null || t.getSymbol() == null) {
			if (this.symbol != t.getSymbol())
				return false;
		} else {
			if (!(this.symbol.getName().equals(t.getSymbol().getName())))
				return false;
		}
		if (this.num == t.getNum()) {
			return true;
		}
		return false;
	}

}
